<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
class Article_Model extends CI_Model 
{
	function __construct() {
        parent::__construct();       
    }
	/************************************* ARTICLE *******************************************/
	function getLatestArticles($limit=4, $user_id=0) 
	{
		$this->db->select('*');
		$this->db->from('article_description');
		$this->db->join('article', 'article.id = article_description.article_id');
		$this->db->order_by("article.created_date", "desc");
		$this->db->where('published', 1);
		//$this->db->where('category_id', $category_id);
		$this->db->where('language_id', $this->session->userdata('langID')); // init in util_helper
        if ($user_id != 0) {
            $this->db->where('user_id', $user_id);
        }
        else {
            $this->db->where('user_id', '0');
        }
		$query = $this->db->get();
		return $query->result_array();
	}
	function getArticles($segment='',$num='', $offset='')
	{
		if (($segment=='') ||(is_numeric($segment)))
		{
			$this->db->limit($num, $offset);
		}
		$this->db->select('*');
		$this->db->from('article_description');
		$this->db->join('article', 'article.id = article_description.article_id');
		$this->db->order_by("article.created_date", "desc");
		$this->db->where('published', 1);
		$this->db->where('language_id', $this->session->userdata('langID')); 
		if (($segment!='') && (!is_numeric($segment)))
		{
			$this->db->like('title_alias', $segment);
			$query = $this->db->get();
			return $query->row();
		}
		else
		{
			$query = $this->db->get();
			return $query->result_array();
		}
	}
	function getCountArticles()
	{
		$this->db->from('article');
		$this->db->where('published', 1);  
		return $this->db->count_all_results();
	}
	function getOtherArticles($urlid)
	{
		
		$this->db->select('*');
		$this->db->from('article_description');
		$this->db->join('article', 'article.id = article_description.article_id');
		$this->db->not_like('title_alias', $urlid);
		$this->db->order_by("article.created_date", "desc");
		//$this->db->limit(10);
		$this->db->where('language_id', $this->session->userdata('langID')); 
		$this->db->where('published', 1);
		$this->db->where('language_id', $this->session->userdata('langID')); 
		$query = $this->db->get();
		return $query->result_array();
	}

	/************************************* STATIC ARTICLE *******************************************/
	function getStaticArticleDetail($alias=false)
	{
    	if (!$alias)return false;
		$this->db->select('*');
		$this->db->from('information_description');
		$this->db->join('information', 'information.information_id = information_description.information_id');
		$this->db->like('title_alias',$alias);
		//$this->db->where('category_id', $category_id);
		$this->db->where('language_id', $this->session->userdata('langID')); // init in util_helper
		$query = $this->db->get();
		return $query->row();
    }
	function getStaticHome($user_id=0)
	{
		$this->db->select('*');
		$this->db->from('information_description');
		$this->db->join('information', 'information.information_id = information_description.information_id');
		$alias = array('bedrijven', 'jongeren', 're-integratie');
		$this->db->where_in('title_alias',$alias);
		$this->db->where('language_id', $this->session->userdata('langID')); // init in util_helper
        if ($user_id != 0) {
            $this->db->where('user_id', $user_id);
        }
        else {
            $this->db->where('user_id');
        }
		$this->db->order_by("title", "asc");
		$query = $this->db->get();
		return $query->result_array();
    			
    }
	/************************** FAQ **********************************/
	function getFAQs($user_id=0) 
	{
        if ($user_id != 0) {
            $str_where = "AND user_id = $user_id";
        }
        else {
            $str_where = "AND (user_id = 0 OR user_id is NULL)";
        }
        $lang_id = $this->session->userdata('langID');
        $sql = "SELECT * FROM faq_description fd INNER JOIN faq f ON f.id=fd.faq_id WHERE published = 1 AND language_id = $lang_id  $str_where";
		$query = $this->db->query($sql);
		return $query->result_array();
	}
}